<?php namespace system\middleware;

use houdunwang\middleware\build\Middleware;

use \system\model\Config as ConfigModel;

class Config implements Middleware{
	//执行中间件
	public function run($next)
	{

		//设置 系统配置项
		$this->setSysConfig();

		$this->setWeixinConfig();

         $next();
	}


	//设置配置项
	private function setSysConfig()
	{
		$model = ConfigModel::find(1);

		$field = $model ?json_decode($model['system'],true):[];

//		p($field);

		v('config',$field);
	}

	//微信配置项
	private function setWeixinConfig()
	{

		$model = ConfigModel::find(1);
		//p($model);
		$field = $model ? json_decode( $model[ 'weixin' ] , true ) : [];

		//p($field);
		//ConfigModel::set('wechat',array_merge(ConfigModel::get('wechat'),$field));

		\houdunwang\config\Config::set('wechat', array_merge(\houdunwang\config\Config::get('wechat'), $field));
//		p(ConfigModel::get('wechat'));

//		file_put_contents(a.php,$field);

	}


}





















